<?php
/**
 * 操作日志服务
 * User: dxk
 * Date: 2020/07/15
 */
namespace App\Service\Core\Admin\Log;

use App\Model\Core\Admin\AdminLogModel;

class AdminLogService
{
    /**
     * 记录操作日志
     * @param string $operate_type
     * @param string $operate_content
     * @param int $operate_id
     * @param string $operate_by
     * @return bool
     */
    public static function addLog(string $operate_type, string $operate_content, int $operate_id, string $operate_by)
    {
        $operate_id = trim($operate_id);
        $operate_by = trim($operate_by);
        $operate_type = trim($operate_type);
        $operate_content = trim($operate_content);
        $ip = easy_ip();
        return AdminLogModel::getInstance()->addLog($operate_type, $operate_content, $operate_id, $operate_by, $ip);
    }

    /**
     * 清理日志
     * @param $keep_time
     * @return int
     */
    public static function clearLog($keep_time)
    {
        $keep_time = date('Y-m-d H:i:s', strtotime($keep_time));
        return AdminLogModel::getInstance()->getConnectionTable()->where('operate_at', "<=", $keep_time)->delete();
    }
}
